**** Right hand side of Figure 8
log using comp_admin, replace

preserve
drop if valar<1982
drop union* ssy* party* num* _merge
ren std_inc_res inc_res
drop if cognitive==.  & betyg_sd==. & inc_res==.

foreach var in betyg_sd  cognitive  inc_res{
	egen std_`var'=std(`var')
}

replace year=valar
drop betyg_sd  cognitive leader
joinby p_id year using  pol_tocomp.dta, unmatched(master)
drop _merge
replace hier_pos ="pop" if hier_pos==""


gen test=""
matrix C =J(30, 5,.)	
local i=0 
local n=0
foreach var in  cognitive  betyg_sd inc_res{
	replace test="`var'"
	local n = `n'+1
	local p=-.35
	foreach level in nom vald  {
	local i = `i'+1	
	local p= `p'+.14	
	areg std_`var' worker_lim  stud age_b30- age_ab64 woman if  hier_pos=="`level'", abs(k_y_p)
	matrix C[`i',1]=_b[worker_lim]
	matrix C[`i',2]=(_b[worker_lim]+1.96*_se[worker_lim])
	matrix C[`i',3]=(_b[worker_lim]-1.96*_se[worker_lim])
	matrix C[`i',4]=`n'+`p'
	matrix C[`i',5]=`p'
	}
	foreach level in leader {
		local i = `i'+1	
		local p= `p'+.14	
		reghdfe std_`var' worker_lim  stud age_b30- age_ab64 woman if hier_pos=="`level'", abs(llkk parti_initial valar)
		matrix C[`i',1]=_b[worker_lim]
		matrix C[`i',2]=(_b[worker_lim]+1.96*_se[worker_lim])
		matrix C[`i',3]=(_b[worker_lim]-1.96*_se[worker_lim])
		matrix C[`i',4]=`n'+`p'
		matrix C[`i',5]=`p'
	}
	foreach level in  parl{
		local i = `i'+1	
		local p= `p'+.14	
		reghdfe std_`var' worker_lim  stud age_b30- age_ab64 woman  if hier_pos=="`level'", abs(parti_initial valar)
		matrix C[`i',1]=_b[worker_lim]
		matrix C[`i',2]=(_b[worker_lim]+1.96*_se[worker_lim])
		matrix C[`i',3]=(_b[worker_lim]-1.96*_se[worker_lim])
		matrix C[`i',4]=`n'+`p'
		matrix C[`i',5]=`p'
	}
}	
svmat C
sum C*
rename C1 estimate
rename C2 upper
rename C3 lower
rename C4 order
gen var="nom" if C5<.-1
replace var="vald" if C5>-.1 & C5<.0
replace var="leader" if C5>.0 & C5<.1
replace var="parl" if C5>.1 & C5!=.
gen measure= "Cognitive Score" if order>.5 & order<1.5
replace measure="Grades" if order>1.5 & order<2.5
replace measure= "Earnings Score" if  order>2.5 & order<3.5
gen position = var
keep if var!=""

twoway (rbar upper lower order if  var=="nom", fcolor(black) lcolor(none) barwidth(.005)) ///
 (scatter estimate order if var=="nom", mcolor(black) msize(large) msymbol(square)) ///
 (rbar upper lower order if var=="vald", fcolor(gs1) lcolor(gs1) barwidth(.005)) ///
 (scatter estimate order if var=="vald", mcolor(gs1) msize(large) msymbol(circle)) ///
 (rbar upper lower order if var=="leader", fcolor(gs1) lcolor(gs1) barwidth(.005)) ///
 (scatter estimate order if var=="leader", mcolor(gs1) msize(large) msymbol(triangle)) ///
 (rbar upper lower order if var=="parl", fcolor(gs1) lcolor(gs1) barwidth(.005)) ///
 (scatter estimate order if var=="parl", mcolor(gs1) msize(large) msymbol(diamond)), ///
 scheme(s1mono) ytitle(Gap between Workers and Non-Workers (SD)) yline(0, lpattern(dash) lcolor(gs7))  ///
 legend(order(2 "Nominated" 4 "Councilors"  6 "Local Leaders" 8 "Parliamentarians") row(2))  xlabel(1 "Grades" 2"Cognitive Score" 3 "Earnings Score"  ) ylabel(, angle(horizontal) grid)
 graph save comp_admin, replace
keep estimate upper lower measure position
save comp_admin, replace
restore
log close
